<template>
	<view>
		<view> 非充值消费--{{currentmemberinfo.name}}</view>
		<view class="mtopclass" style="display: flex; align-items: center;">
			<view>消费金额：</view>
			<view><uni-easyinput placeholder="请填写余额充值金额" v-model="balancenumber"></uni-easyinput>
			</view>
		</view>
		<view class="mtopclass" style="display: flex; align-items: center;">
			<view>代金券：</view>
			<view><uni-easyinput placeholder="请填写代金券充值金额" v-model="vouchernumber"></uni-easyinput>
			</view>
		</view>
		<view class="mtopclass">
			<uni-easyinput type="textarea" placeholder="请填写备注信息" v-model="remark"></uni-easyinput>
		</view>
		<view style="margin-top: 50rpx;">
			<cc-wxBtn :title="operater.name" @menuClick="selecterpcorpaccount"></cc-wxBtn>
		</view>

		<view class="mtopclass" style="display: flex;justify-content: space-around;">
			<button type="warn" size="mini" @click="addRechargedConsumptionCancle">取消</button>
			<button type="primary" size="mini" @click="addRechargedConsumptionSubmit">确定</button>
		</view>
		<!-- 选择操作人窗口开始 -->
		<uni-popup ref="selectmemberbalancewindow">
			<view
				style="width: 50vw; max-width: 1000rpx; height: auto; max-height: 90vh; background-color: white; border-radius: 30rpx; padding: 30rpx;">
				<view>
					<uni-search-bar v-model="searchkeyword" @input="geterpcorpaccount"></uni-search-bar>
					<view style="height: 80vh; overflow-y: auto;">
						<view v-for="(item,index) in erpcorpaccount" :key="index">
							<cc-wxBtn :title="item.name" @menuClick="operatselectsubmit(item)"></cc-wxBtn>
						</view>
					</view>
				</view>

			</view>
		</uni-popup>
		<!-- 选择操作人窗口结束 -->
	</view>
</template>

<script>
	import {
		postrequest
	} from '../../common/apis.js';
	export default {
		name: "unRechargedConsumption",
		data() {
			return {
				currentmemberinfo: uni.getStorageSync('currentmemberinfo'),
				balancenumber: 0,
				pointsnumber: 0,
				vouchernumber: 0,
				remark: '',
				operater: {},
				pagesize: 20,
				searchkeyword: '',
				erpcorpaccount: '',
			};
		},
		methods: {
			selecterpcorpaccount() {
				this.geterpcorpaccount()
				this.$refs.selectmemberbalancewindow.open('center')
			},
			operatselectsubmit(item) {
				this.operater = item
				this.$refs.selectmemberbalancewindow.close()
			},
			geterpcorpaccount() {
				console.log(this.searchkeyword)
				let data = {
					username: uni.getStorageSync('username'),
					password: uni.getStorageSync('password'),
					page: 1,
					pagesize: this.pagesize,
					searchkeyword: this.searchkeyword
				}
				let url = 'https://www.jsyufang.com/yixun/api/get_erp_corp_account/index.asp'
				let errmessage = '获取会员余额日志接口调用失败'
				postrequest(url, data, errmessage, true)
					.then((res) => {
						console.log(res.data.data)
						this.erpcorpaccount = res.data.data
						this.total = res.data.total
					})
			},
			addRechargedConsumptionCancle() {
				this.$emit('operate', 'cancle')
			},
			addRechargedConsumptionSubmit() {
				this.pointsnumber = this.balancenumber * this.currentmemberinfo.pointsRate
				console.log(this.currentmemberinfo.pointsRate)
				console.log(this.currentmemberinfo.member_id)
				console.log(this.balancenumber)
				console.log(this.remark)
				console.log(this.operater.id)
				if (this.balancenumber == 0 && this.vouchernumber == 0) {
					uni.showToast({
						title: '操作数量不可为0',
						icon: 'error'
					})
					return
				}
				if (this.remark == '') {
					uni.showToast({
						title: '请填写备注信息',
						icon: 'error'
					})
					return
				}
				if (!this.operater.id) {
					uni.showToast({
						title: '请选择操作人',
						icon: 'error'
					})
					return
				}
				let data = {
					username: uni.getStorageSync('username'),
					password: uni.getStorageSync('password'),
					member_id: this.currentmemberinfo.member_id,
					balancenumber: 0,
					pointsnumber: this.pointsnumber,
					vouchernumber: 0 - this.vouchernumber,
					remark: this.remark,
					operater: this.operater.id
				}
				let url = 'https://www.jsyufang.com/yixun/api/addbalancelog/index.asp'
				let errmessage = '添加余额日志接口调用失败'
				postrequest(url, data, errmessage, true)
					.then((res) => {
						console.log(res.data.data)
						this.$emit('operate', 'closeme')
					})
			},
		}
	}
</script>

<style>
	.mtopclass {
		padding-top: 50rpx;
	}
</style>